import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;



public class Destination extends Node_design
{
	ServerSocket server;
	Socket client;
	final static int port=3696;
	public Destination() throws IOException
	{	
		super("Receiver");
		
	}

	private void startServer() throws IOException 
	{
		server=new ServerSocket(port);
		
		while(true)
		{
			client=server.accept();
			DestinationThread dt=new DestinationThread(client,this);
			Thread t=new Thread(dt);
			t.start();
		}

	}

	public static void main(String[] args) throws IOException 
	{
		Destination d = new Destination();
		d.storeInDb();
		d.startServer();
	
	}

	private void storeInDb() throws UnknownHostException 
	{
		String query="insert into node values(\""+InetAddress.getLocalHost().getHostAddress()+"\","+port+",\"destination\")";
		System.out.println(query);
		Queries.update(query);
			
	}

}
